﻿<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="zh-CN">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<style type="text/css">
<!--

body {
	background:transparent;
	margin:0 10px;
	font-size:12px;
}
div {
	margin:10px 0;
}
form,ul {
	margin:0px;
	padding:0px;
}
ul {
	display:block;
	clear:both;
	height:21px;
}
li {
	width:18px;
	display:block;
	float:left;
	margin-right:3px;
	padding:0;
	border: 1px solid #bbb;
	border-top:0;
	background-color:#fff;
	height:16px;
	text-align:center;
	cursor:default;
}
li.current {
	background-color:#efefef;
}
input {
	display:block;
	width:100%;
}
--></style>
</head>
<body>
<form id="uploadForm" name="uploadForm" method="POST" enctype="multipart/form-data" action="/upload.aspx?" target="_self">
	<script type="text/javascript">
		var qs = location.search.split('=')[1] * 1;
		if(qs > 1) {
			document.write('<ul id="fileindex"><li class="current" ondblclick="removeSelectedFile(this)" onclick="showFile(this)">*</li></ul>');
			document.write('<input name="upfile1" type="file" onchange="selectFile(this)" onkeypress="return false" oncontextmenu="return false" />');
			
			var fc = 1;
			var fi = document.getElementById("fileindex");
			var current = fi.firstChild;
			
			var fm = document.getElementById("uploadForm");
			fm.className = "multi";
			
			
			function selectFile(ctrl) {
				if(ctrl.value.length > 0) {
					if(current.innerHTML == "*") {
						current.title = ctrl.value;
						var idx = fi.childNodes.length;
						current.innerHTML = idx.toString();
						
						if(idx < qs) {
							current.className = "";
							current = current.cloneNode(true);
							current.innerHTML = "*";
							current.className = "current";
							fi.appendChild(current);
							
							fc++;
							var newctrl = ctrl.cloneNode(true);
							ctrl.style.display = "none";
							newctrl.setAttribute("name", "upfile" + fc.toString());
							newctrl.value = "";
							if(newctrl.value.length > 0) {
								newctrl.outerHTML = newctrl.outerHTML;
							}
							fm.appendChild(newctrl);
						}
						
					} else {
						current.title = ctrl.value;
					}
				}
				else {
					removeSelectedFile(current);
				}
			}
			
			function showFile(ctrl) {
				current.className = "";
				if(current.innerHTML != "*") {
					fm.elements[current.innerHTML - 1].style.display = "none";
				} else {
					fm.elements[fm.elements.length - 1].style.display = "none";
				}
				current = ctrl;
				ctrl.className = "current";
				if(ctrl.innerHTML != "*") {
					fm.elements[ctrl.innerHTML - 1].style.display = "block";
				} else {
					fm.elements[fm.elements.length - 1].style.display = "block";
				}
			}
			
			function removeSelectedFile(ctrl) {
				if(ctrl.innerHTML != "*") {
					if(fi.lastChild.innerHTML != "*") {
						while(!!(ctrl = ctrl.nextSibling)) {
							ctrl.innerHTML--;
						}
						
						ctrl = fm.elements[current.innerHTML - 1];
						var newctrl = ctrl.cloneNode(true);
						fm.removeChild(ctrl);
						newctrl.value = "";
						fm.appendChild(newctrl);
						current.innerHTML = "*";
						fi.appendChild(current);
					} else {
						while(!!(current = current.nextSibling) && current.innerHTML != "*") {
							current.innerHTML--;
						}
						fi.removeChild(ctrl);
						fm.removeChild(fm.elements[ctrl.innerHTML - 1]);
						current.className = "current";
						fm.elements[fm.elements.length - 1].style.display = "block";
					}
				}
			}
		} else {
			document.write('<div><input name="upfile" type="file" onkeydown="event.returnValue=false" oncontextmenu="event.returnValue=false" /><div>');
		}
	</script>
</form>
</body>
</html>

